package com.djl.rabbitmq.six;

import com.djl.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * @program: rabbitmq-hello
 * @description: 发消息给交换机
 * @author: Mr.dai
 * @create: 2021-09-12 15:53
 **/

public class DirectLog {
        public static final  String EXCHANGE_NAME ="direct_log";

    public static void main(String[] args) throws Exception {
        //获取信道
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String msg=scanner.next();
            channel.basicPublish(EXCHANGE_NAME,"info",null,msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者发出消息:"+msg);
        }

    }
}
